home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Panel Editor / Source / PrinterGX.cpp < prev    next >
Encoding:
Text File  |  1995-12-08  |  17.8 KB  |  667 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PrinterGX.cpp
  3.  
  4.     Contains:    QuickDraw GX printing support for OpenDoc printing utility
  5.  
  6.     Written by:    Thomas Weisbach, Jens Alfke
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11.  
  12.  
  13. // -- OpenDoc --
  14.  
  15. #ifndef _ALTPOINT_
  16. #include <AltPoint.h>
  17. #endif
  18.  
  19. #ifndef SOM_ODCanvas_xh
  20. #include <Canvas.xh>
  21. #endif
  22.  
  23. #ifndef SOM_ODClipboard_xh
  24. #include <Clipbd.xh>
  25. #endif
  26.  
  27. #ifndef SOM_Module_OpenDoc_Commands_defined
  28. #include <CmdDefs.xh>
  29. #endif
  30.  
  31. #ifndef SOM_ODDispatcher_xh
  32. #include <Disptch.xh>
  33. #endif
  34.  
  35. #ifndef SOM_ODFacet_xh
  36. #include <Facet.xh>
  37. #endif
  38.  
  39. #ifndef SOM_ODFrame_xh
  40. #include <Frame.xh>
  41. #endif
  42.  
  43. #ifndef SOM_ODMenuBar_xh
  44. #include <MenuBar.xh>
  45. #endif
  46.  
  47. #ifndef SOM_ODSession_xh
  48. #include <ODSessn.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODStorageSystem_xh
  52. #include <ODStor.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODPart_xh
  56. #include <Part.xh>
  57. #endif
  58.  
  59. #ifndef SOM_ODPlatformTypeList_xh
  60. #include <PfTypLs.xh>
  61. #endif
  62.  
  63. #ifndef SOM_ODShape_xh
  64. #include <Shape.xh>
  65. #endif
  66.  
  67. #ifndef SOM_Module_OpenDoc_StdProps_defined
  68. #include <StdProps.xh>
  69. #endif
  70.  
  71. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  72. #include <StdTypes.xh>
  73. #endif
  74.  
  75. #ifndef SOM_ODTransform_xh
  76. #include <Trnsform.xh>
  77. #endif
  78.  
  79. #ifndef SOM_ODWindowState_xh
  80. #include <WinStat.xh>
  81. #endif
  82.  
  83. // -- OpenDoc Utilities --
  84.  
  85. #ifndef _EXCEPT_
  86. #include <Except.h>
  87. #endif
  88.  
  89. #ifndef _ISOSTR_
  90. #include <ISOStr.h>
  91. #endif
  92.  
  93. #ifndef _DLOGUTIL_
  94. #include <DlogUtil.h>
  95. #endif
  96.  
  97. #ifndef _ODDEBUG_
  98. #include <ODDebug.h>
  99. #endif
  100.  
  101. #ifndef _ODNEW_
  102. #include <ODNew.h>
  103. #endif
  104.  
  105. #ifndef _ODUTILS_
  106. #include <ODUtils.h>
  107. #endif
  108.  
  109. #ifndef _STORUTIL_
  110. #include <StorUtil.h>
  111. #endif
  112.  
  113. #ifndef _TEMPOBJ_
  114. #include <TempObj.h>
  115. #endif
  116.  
  117. #ifndef _USERSRCM_
  118. #include <UseRsrcM.h>
  119. #endif
  120.  
  121. // -- MacToolbox --
  122.  
  123. #ifndef __GXGRAPHICS__
  124. #include <GXGraphics.h>
  125. #endif
  126.  
  127. #ifndef __TEXTUTILS__
  128. #include <TextUtils.h>
  129. #endif
  130.  
  131. // -- Printer --
  132. #define _PRINTER_PRIVATE_
  133. #ifndef _PRINTER_
  134. #include "Printer.h"
  135. #endif
  136.  
  137. #pragma segment Printer
  138.  
  139.  
  140. //---------------------------------------------------------------------------------
  141. // THROW_IF_JOB_ERROR  [static]
  142. //---------------------------------------------------------------------------------
  143.  
  144. static void
  145. THROW_IF_JOB_ERROR( gxJob job )
  146. {
  147.     OSErr err= GXGetJobError(job);
  148.     if( err ) THROW(err);
  149. }
  150.  
  151.  
  152. //=================================================================================
  153. // PrintingEventHandler declaration
  154. //    A stack-based object that temporarily installs a GX printing event override
  155. //    to forward some events (activate/deactivate/etc.) to the OpenDoc dispatcher.
  156. //=================================================================================
  157.  
  158. class PrintingEventHandler :Destructo
  159. {
  160. public:
  161.     PrintingEventHandler(Environment* ev, ODSession* session, gxJob job);
  162.     ~PrintingEventHandler();
  163.     
  164.     static OSErr PrintingEventOverride(EventRecord *anEvent, Boolean filterEvent);
  165.  
  166. private:
  167.     static Environment*     sEv;
  168.     static ODSession*        sSession;
  169.     static gxJob            sgxJob;
  170.  
  171.     gxJob                    fgxJob;
  172.     GXPrintingEventUPP        fPrintingEventOverrideProcPtr;
  173. };
  174.  
  175.  
  176. //=================================================================================
  177. // CGXPrinter implementation
  178. //=================================================================================
  179.  
  180. //---------------------------------------------------------------------------------
  181. // CGXPrinter::CGXPrinter
  182. //---------------------------------------------------------------------------------
  183.  
  184. CGXPrinter::CGXPrinter( )
  185. {
  186.     fJob = kODNULL;
  187.     fViewPort = kODNULL;
  188.     fQDPort = kODNULL;
  189.     fPrintAShapeProcPtr = kODNULL;
  190.     fJobStarted = kODFalse;
  191.     fPageOpen = kODFalse;
  192. }
  193.  
  194. //---------------------------------------------------------------------------------
  195. // CGXPrinter::~CGXPrinter
  196. //---------------------------------------------------------------------------------
  197.  
  198. CGXPrinter::~CGXPrinter()
  199. {
  200.     if( fJob ) {
  201.         GXDisposeJob(fJob);
  202.     }
  203.     if( fPrintingOpen ) {
  204.         GXExitPrinting();
  205.         fPrintingOpen = kODFalse;
  206.     }
  207. }
  208.     
  209. //---------------------------------------------------------------------------------
  210. // CGXPrinter::Initialize
  211. //---------------------------------------------------------------------------------
  212.  
  213. void CGXPrinter::Initialize( Environment *ev, ODStorageUnit *su )
  214. {
  215.     // We can't open and close GX printing on every operation the way we could
  216.     // with QD. We have to leave it open for as long as we are going to use it,
  217.     // or else objects like fJob will be invalidated. So we open it now and
  218.     // don't close it until we get to the destructor.
  219.     
  220.     inherited::Initialize(ev,su);
  221.     THROW_IF_ERROR( GXInitPrinting() );
  222.     fPrintingOpen = kODTrue;
  223. }
  224.  
  225. //---------------------------------------------------------------------------------
  226. // CGXPrinter::ReadJobFromHandle
  227. //---------------------------------------------------------------------------------
  228.  
  229. ODPlatformPrintJob CGXPrinter::ReadJobFromHandle(ODValueType valueType, ODHandle h)
  230. {
  231.     // We can either read a streamed-out GX job or convert an old-style THPrint.
  232.     
  233.     if( ODISOStrEqual(valueType,kODTypeGXPageSetup) ) {
  234.         fJob = GXUnflattenJobFromHdl(kODNULL, (Handle)h);
  235.         
  236.     } else if( ODISOStrEqual(valueType,kODTypeQuickDrawPageSetup) ) {
  237.         if( GXNewJob(&fJob) == noErr )
  238.             GXConvertPrintRecord(fJob, (THPrint)h);
  239.         
  240.     } else
  241.         WARN("Unknown value type");
  242.         
  243.     ODDisposeHandle(h);
  244.     if( fJob && GXGetJobError(fJob) ) {
  245.         WARN("Error %d reading GX job",GXGetJobError(fJob));
  246.         if( fJob ) GXDisposeJob(fJob);
  247.         fJob = kODNULL;
  248.     }
  249.     
  250.     return (ODPlatformPrintJob)fJob;
  251. }
  252.  
  253. //---------------------------------------------------------------------------------
  254. // CGXPrinter::CreateNewJob
  255. //---------------------------------------------------------------------------------
  256.  
  257. ODPlatformPrintJob CGXPrinter::CreateNewJob()
  258. {
  259.     // Throw an exception if we can't create a print job, since we will certainly
  260.     // not be able to continue!
  261.     
  262.     THROW_IF_ERROR( GXNewJob(&fJob) );
  263.     return (ODPlatformPrintJob) fJob;
  264. }
  265.  
  266. //---------------------------------------------------------------------------------
  267. // CGXPrinter::CopyJobToHandle
  268. //---------------------------------------------------------------------------------
  269.  
  270. ODHandle CGXPrinter::CopyJobToHandle( )
  271. {
  272.     ODHandle jobHandle = ODNewHandle(0);
  273.     GXFlattenJobToHdl(fJob, (Handle)jobHandle);
  274.     if( GXGetJobError(fJob) ) {
  275.         ODDisposeHandle(jobHandle);
  276.         THROW_IF_ERROR(GXGetJobError(fJob));
  277.     }
  278.     return jobHandle;
  279. }
  280.  
  281. //---------------------------------------------------------------------------------
  282. // CGXPrinter::GetPageRect
  283. //---------------------------------------------------------------------------------
  284.  
  285. ODRect CGXPrinter::GetPageRect( Environment *ev )
  286. {
  287.     // Doesn't handle custom page formats; assumes all pages have same bbox.
  288.     
  289.     ODRect pageRect;
  290.     
  291.     this->GetPlatformPrintJob(ev);        // Force internalization of fJob
  292.     
  293.     gxFormat pageFormat = GXGetJobFormat(fJob, 1);
  294.     GXGetFormatDimensions(pageFormat, (gxRectangle*) &pageRect, kODNULL);
  295.     
  296.     return pageRect;
  297. }
  298.  
  299. //---------------------------------------------------------------------------------
  300. // CGXPrinter::CreatePrintingPlatformCanvas
  301. //---------------------------------------------------------------------------------
  302.  
  303. ODPlatformCanvas
  304. CGXPrinter::CreatePrintingPlatformCanvas( Environment* ev, ODGraphicsSystem g,
  305.                                             ODFrame *initiator, ODShape *area )
  306. {
  307.     switch( g ) {
  308.         case kODQuickDrawGX: {
  309.             // Start print job & create printing viewport.
  310.             long firstPage, lastPage;
  311.             GXGetJobPageRange(fJob, &firstPage, &lastPage);
  312.             ODUShort pageCount = this->CountPages(ev, area);
  313.             if ( lastPage > pageCount )
  314.                 lastPage = pageCount;
  315.         
  316.             Str255 windowTitle;
  317.             {
  318.                 TempODWindow w = fSession->GetWindowState(ev)->AcquireFrontRootWindow(ev);
  319.                 GetWTitle( w->GetPlatformWindow(ev), windowTitle );
  320.             }
  321.             
  322.             GXStartJob(fJob, windowTitle, lastPage - firstPage + 1);
  323.             THROW_IF_ERROR(GXGetJobError(fJob));
  324.             fJobStarted = kODTrue;
  325.             
  326.             WASSERT(fViewPort==kODNULL);
  327.             fViewPort = GXNewViewPort(gxScreenViewDevices);
  328.             return (ODPlatformCanvas) fViewPort;
  329.             // The viewport isn't hooked up to the job yet,
  330.             // but it will be in OpenPage.
  331.         }
  332.         
  333.         case kODQuickDraw: {
  334.             // Find the frame's window's port:
  335.             TempODWindow window = initiator->AcquireWindow(ev);
  336.             fQDPort = window->GetPlatformWindow(ev);
  337.  
  338.             fPrintAShapeProcPtr = NewgxShapeSpoolProc(CGXPrinter::PrintAShape);
  339.         
  340.             return (ODPlatformCanvas) fQDPort;
  341.         }
  342.         
  343.         default: {
  344.             THROW(kODErrInvalidGraphicsSystem);
  345.             return kODNULL;
  346.         }
  347.     }
  348. }
  349.  
  350. //---------------------------------------------------------------------------------
  351. // CGXPrinter::OpenPage
  352. //---------------------------------------------------------------------------------
  353.  
  354. void CGXPrinter::OpenPage( Environment*, ODUShort page )
  355. {
  356.     // Get the specific page format. (note: we don't support
  357.     // custom page setup, yet, so we always get the first page's
  358.     // format).
  359.     
  360.     gxFormat pageFormat = GXGetJobFormat(fJob, 1);
  361.     
  362.     GXStartPage(fJob, page, pageFormat, 1, &fViewPort);                                
  363.     
  364.     THROW_IF_JOB_ERROR(fJob);
  365.     
  366.     fPageOpen = kODTrue;
  367.  
  368.     // Now install the QD->GX translator:
  369.     Point     patStretch = {1, 1};
  370.     Rect    everywhereRect = {0,0,32767,32767};
  371.  
  372.     GXInstallQDTranslator(fQDPort,
  373.                           gxDefaultOptionsTranslation,
  374.                           &everywhereRect, &everywhereRect,
  375.                           patStretch, 
  376.                           fPrintAShapeProcPtr,
  377.                           this);
  378. }
  379.  
  380. //---------------------------------------------------------------------------------
  381. // CGXPrinter::ClosePage
  382. //---------------------------------------------------------------------------------
  383.  
  384. void 
  385. CGXPrinter::ClosePage( Environment* )
  386. {
  387.     if( fPageOpen ) {    
  388.         // Finish the page.
  389.         if( fQDPort )
  390.             GXRemoveQDTranslator(fQDPort, kODNULL);
  391.  
  392.         GXFinishPage(fJob);
  393.         
  394.         fPageOpen = kODFalse;
  395.         
  396.         THROW_IF_JOB_ERROR(fJob);
  397.     }
  398. }
  399.  
  400. //---------------------------------------------------------------------------------
  401. // CGXPrinter::CleanupPrintingEnv
  402. //---------------------------------------------------------------------------------
  403.  
  404. void CGXPrinter::CleanupPrintingEnv(Environment* ev, ODFrame* initiator)
  405. {
  406.     // This routine should not throw exeptions and must call the inherited method.
  407.     
  408.     if( fJobStarted ) {
  409.         fJobStarted = kODFalse;
  410.         GXFinishJob(fJob);
  411.         if( GXGetJobError(fJob) )
  412.             WARN("Error %d finishing job",GXGetJobError(fJob));
  413.     }
  414.     
  415.     if( fPrintAShapeProcPtr ) {
  416.         DisposeRoutineDescriptor(fPrintAShapeProcPtr);
  417.         fPrintAShapeProcPtr = kODNULL;
  418.     }
  419.  
  420.     if( fViewPort ) {
  421.         GXDisposeViewPort(fViewPort);
  422.         fViewPort = kODNULL;
  423.     }
  424.     
  425.     inherited::CleanupPrintingEnv(ev,initiator);
  426. }
  427.  
  428. //---------------------------------------------------------------------------------
  429. // CGXPrinter::EnableMenus
  430. //---------------------------------------------------------------------------------
  431.  
  432. void CGXPrinter::EnableMenus( Environment* ev, ODBoolean enable )
  433. {
  434.     // While printing/page-setup dialogs are up, we need to disable all irrelevant
  435.     // menu commands except the standard Undo/Cut/Copy/Paste/Clear. We also need
  436.     // to fill out an EditMenuRec for GX to tell it where those commands are.
  437.     
  438.     ODWindowState* windowState = fSession->GetWindowState(ev);
  439.     TempODMenuBar mbar = windowState->AcquireCurrentMenuBar(ev);
  440.  
  441.     if (enable)
  442.     {
  443.         // Called after dialog goes away.
  444.         mbar->EnableAll(ev);
  445.         mbar->EnableCommand(ev, kODCommandAbout, kODTrue);
  446.     }
  447.     else
  448.     {
  449.         // Called before dialog comes up.
  450.         mbar->DisableAll(ev);
  451.         mbar->EnableCommand(ev, kODCommandAbout, kODFalse);
  452.         
  453.         ODMenuID menuID;
  454.         
  455.         mbar->GetMenuAndItem(ev, kODCommandUndo, &(fEditMenuRec.editMenuID), &(fEditMenuRec.undoItem));
  456.         mbar->GetMenuAndItem(ev, kODCommandCut, &menuID, &(fEditMenuRec.cutItem));
  457.         mbar->GetMenuAndItem(ev, kODCommandCopy, &menuID, &(fEditMenuRec.copyItem));
  458.         mbar->GetMenuAndItem(ev, kODCommandPaste, &menuID, &(fEditMenuRec.pasteItem));
  459.         mbar->GetMenuAndItem(ev, kODCommandClear, &menuID, &(fEditMenuRec.clearItem));
  460.  
  461.         mbar->EnableCommand(ev, kODCommandEditMenu,     kODTrue);
  462.         mbar->EnableCommand(ev, kODCommandRedo,         kODFalse);
  463.         mbar->EnableCommand(ev, kODCommandUndo,         kODTrue);
  464.         mbar->EnableCommand(ev, kODCommandCut,             kODTrue);
  465.         mbar->EnableCommand(ev, kODCommandCopy,         kODTrue);
  466.         mbar->EnableCommand(ev, kODCommandPaste,         kODTrue);
  467.         mbar->EnableCommand(ev, kODCommandPasteAs,         kODFalse);
  468.         mbar->EnableCommand(ev, kODCommandClear,         kODTrue);
  469.         mbar->EnableCommand(ev, kODCommandSelectAll,     kODFalse);
  470.         mbar->EnableCommand(ev, kODCommandGetPartInfo,     kODFalse);
  471.         mbar->EnableCommand(ev, kODCommandPreferences,     kODFalse);
  472.         mbar->EnableCommand(ev, kODCommandViewAsWin,     kODFalse);
  473.     
  474.         // Replace contents of Undo menu items with standard strings from rsrc:
  475.         CUsingLibraryResources r;
  476.  
  477.         ODIText* menuText = GetODITextInd(rMenuStrID, kPMUndoStrIndex);
  478.         mbar->SetItemString(ev, kODCommandUndo, menuText);
  479.         DisposeIText(menuText);
  480.  
  481.         menuText = GetODITextInd(rMenuStrID, kPMRedoStrIndex);
  482.         mbar->SetItemString(ev, kODCommandRedo, menuText);
  483.         DisposeIText(menuText);
  484.     }
  485.  
  486.     mbar->Display(ev);
  487. }
  488.     
  489. //---------------------------------------------------------------------------------
  490. // CGXPrinter::RunPageSetupDialog
  491. //---------------------------------------------------------------------------------
  492.  
  493. ODBoolean CGXPrinter::RunPageSetupDialog( Environment *ev )
  494. {
  495.     PrintingEventHandler    idleHandler(ev, fSession, fJob);
  496.     
  497.     this->EnableMenus(ev,kODFalse);
  498.     
  499.     ODBoolean success = (GXJobDefaultFormatDialog(fJob, &fEditMenuRec) == gxOKSelected);
  500.     
  501.     this->EnableMenus(ev,kODTrue);
  502.     
  503.     THROW_IF_JOB_ERROR(fJob);
  504.     
  505.     return success;
  506. }
  507.  
  508. //---------------------------------------------------------------------------------
  509. // CGXPrinter::RunPrintDialog
  510. //---------------------------------------------------------------------------------
  511.  
  512. ODBoolean CGXPrinter::RunPrintDialog(Environment* ev)
  513. {
  514.     ODBoolean success;
  515.  
  516.     TRY
  517.         // Display the Print dialog.
  518.         PrintingEventHandler    idleHandler(ev, fSession, fJob);
  519.  
  520.         this->EnableMenus(ev,kODFalse);
  521.         success = (GXJobPrintDialog(fJob, &fEditMenuRec) == gxOKSelected);
  522.         this->EnableMenus(ev,kODTrue);
  523.     
  524.         THROW_IF_JOB_ERROR(fJob);
  525.     CATCH_ALL
  526.         success = kODFalse;
  527.     ENDTRY
  528.  
  529.     return success;
  530. }
  531.  
  532. //---------------------------------------------------------------------------------
  533. // CGXPrinter::PrintDocument
  534. //---------------------------------------------------------------------------------
  535.  
  536. void CGXPrinter::DoPrint(Environment* ev, ODShape* area)
  537. {
  538.     PrintingEventHandler    idleHandler(ev, fSession, fJob);
  539.  
  540.     this->EnableMenus(ev, kODFalse);
  541.     
  542.     // Check to see if the user wanted to print everything, or just
  543.     // selected pages.
  544.     long firstPage, lastPage;
  545.     GXGetJobPageRange(fJob, &firstPage, &lastPage);
  546.  
  547.     ODULong pageCount = this->CountPages(ev, area);
  548.     if ( lastPage > pageCount ) 
  549.         lastPage = pageCount;
  550.  
  551.     // Print the pages, one at a time.
  552.     for (int page = firstPage; page <= lastPage; page++)
  553.     {
  554.         this->PrintPage(ev, page, area);            // SHAZAM!
  555.     }
  556.  
  557.     this->EnableMenus(ev, kODTrue);
  558. }
  559.  
  560. //---------------------------------------------------------------------------------
  561. // CGXPrinter::PrintAShape  [static method]
  562. //---------------------------------------------------------------------------------
  563.  
  564. OSErr CGXPrinter::PrintAShape(gxShape currentShape, long refCon)
  565. {
  566.     // This is a static method called by the QD->GX translator. Any QuickDraw
  567.     // command in the facet's QD port will be converted to a GX shape and sent here.
  568.     // We just draw it into the printing viewport so the printer will get it.
  569.     
  570.     CGXPrinter*     printer     = (CGXPrinter*)refCon;
  571.     gxShapeType        shapeType     = GXGetShapeType(currentShape);
  572.     ODRect            pageRect    = printer->GetPageRect(somGetGlobalEnvironment());
  573.     
  574.     if ((shapeType == gxEmptyType) || (shapeType == gxFullType) || (shapeType == gxPictureType)
  575.             || GXTouchesBoundsShape((gxRectangle*)&pageRect, currentShape))
  576.     {
  577.         GXSetShapeViewPorts(currentShape, 1, &printer->fViewPort);
  578.         GXDrawShape(currentShape);
  579.     }
  580.     
  581.     return GXGetGraphicsError(kODNULL);
  582. }
  583.  
  584.  
  585. //=================================================================================
  586. // PrintingEventHandler implementation
  587. //=================================================================================
  588.  
  589. Environment*     PrintingEventHandler::sEv = kODNULL;
  590. ODSession*        PrintingEventHandler::sSession = kODNULL;
  591. gxJob            PrintingEventHandler::sgxJob = kODNULL;
  592.  
  593. //---------------------------------------------------------------------------------
  594. // PrintingEventHandler::PrintingEventHandler
  595. //---------------------------------------------------------------------------------
  596.  
  597. PrintingEventHandler::PrintingEventHandler(Environment* ev, ODSession* session, gxJob job)
  598. {
  599.     sEv = ev; 
  600.     sSession = session;
  601.     sgxJob = job;
  602.     
  603.     fgxJob = job;
  604.     fPrintingEventOverrideProcPtr = NewGXPrintingEventProc(PrintingEventHandler::PrintingEventOverride);
  605.  
  606.     GXInstallApplicationOverride(fgxJob, gxPrintingEventMsg, fPrintingEventOverrideProcPtr);
  607. }
  608.  
  609. //---------------------------------------------------------------------------------
  610. // PrintingEventHandler::~PrintingEventHandler
  611. //---------------------------------------------------------------------------------
  612.  
  613. PrintingEventHandler::~PrintingEventHandler()
  614. {
  615.     GXInstallApplicationOverride(fgxJob, gxPrintingEventMsg, kODNULL);
  616.  
  617.     DisposeRoutineDescriptor(fPrintingEventOverrideProcPtr);
  618.  
  619.     sEv = kODNULL;
  620.     sSession = kODNULL;
  621. }
  622.  
  623. //---------------------------------------------------------------------------------
  624. // PrintingEventHandler::PrintingEventOverride
  625. //---------------------------------------------------------------------------------
  626.  
  627. OSErr PrintingEventHandler::PrintingEventOverride(EventRecord* anEvent, Boolean filterEvent)
  628. {
  629.     // this is a static method used as a callback by GX...
  630.     
  631.     WASSERT(sSession != kODNULL);
  632.     WASSERT(sEv != kODNULL);
  633.  
  634.     //WARN("Within SBPrintingEventHandler::SBPrintingEventOverride");
  635.  
  636.     if (!filterEvent)
  637.     {
  638.         switch(anEvent->what)
  639.         {
  640.             case nullEvent:
  641.             case mouseDown:
  642.             case keyDown:
  643.             case autoKey:
  644.                 break;
  645.             
  646.             case osEvt:
  647.                 // Update the job on a resume event in case user changed printer in Finder:
  648.                 if( ((anEvent->message>>24) & 0x00FF)==0x01 && (anEvent->message & 0x01) ) {
  649.                     GXUpdateJob(sgxJob);
  650.                 }
  651.                 // continue to default case:
  652.                 
  653.             default:
  654.                 TRY{
  655.                     ODDispatcher* dispatcher = sSession->GetDispatcher(sEv);
  656.                     if (dispatcher)
  657.                         dispatcher->Dispatch(sEv, (ODEventData*)anEvent);
  658.                 }CATCH_ALL{
  659.                     WARN("Error dispatching event");
  660.                 }ENDTRY
  661.                 break;
  662.         }
  663.     }
  664.     
  665.     return noErr;
  666. }
  667.